<template>
	<div id="user_apply">
		<h3 class="text-info">用户申请版主列表</h3>
		<div >
			<table class="table ">
				<tr>
					<th>申请用户</th>
					<th>版块名称</th>
					<th>版块描述</th>
					<th>申请时间</th>
					<th>申请结果</th>
					<th>操作</th>
				</tr>
				<tr v-for="apply in applys" :key="apply.index">
					<td>{{apply.username}}</td>
					<td>{{apply.forumName}}</td>
					<td>{{apply.forumContent}}</td>
					<td>{{apply.applyTime | timef}}</td>
					<td>{{apply.statusInfo}}</td>
					<td v-if="apply.status == 0"><button @click="reject(apply.id)" class="btn btn-danger">拒绝</button>
						<button @click="accept(apply.id)" class="btn btn-success">同意</button></td>
				</tr>

			</table>
		</div>

	</div>
</template>

<script>
	export default {
		data() {
			return {
				applys: {},
			}
		},
		created() {
			this.getAllApply();
		},
		methods: {
			getAllApply() {
				this.$http.get('/api/getAllApply').then(data => {
					if(data.status == 200) {
						this.applys = data.body;
						this.changeApply();
					}
				}, err => {
					console.log(err);
				})
			},
			changeApply() {
				for(var i = 0; i < this.applys.length; i++) {
					if(this.applys[i].status == 0) {
						this.applys[i].statusInfo = "申请中...";
					}
					if(this.applys[i].status == 1) {
						this.applys[i].statusInfo = "申请成功";
					}
					if(this.applys[i].status == 2) {
						this.applys[i].statusInfo = "申请失败";
					}
				}
			},
			accept(applyId) {
				this.$http.get('/api/acceptApply', {
					params: {
						id: applyId
					}
				}).then(data => {
					if(data.status == 200) {
						this.getAllApply();
					}
				}, err => {
					console.log(err);
				})
			},
			reject(id) {
				this.$http.get('/api/rejectApply', {
					params: {
						id: id
					}
				}).then(data => {
					if(data.status == 200) {
						this.getAllApply();
					}
				}, err => {
					console.log(err);
				})
			}
		}
	}
</script>

<style scoped>
	#user_apply {
		width: 700px;
		margin:0 auto;
	}
</style>